﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AdaptiveAgents.Loggers
{
    /// <summary>
    /// Logger that writes data to the screen
    /// </summary>
    public class ScreenLogger : Logger
    {
        /// <summary>
        /// Constructor
        /// </summary>
        public ScreenLogger() { }
         

        /// <summary>
        /// Does nothing since there's no stream to closemo
        /// </summary>
        public override void Close() { }

        /// <summary>
        /// Writes a message accroding to different types and data.
        /// </summary>
        /// <param name="message">message type</param>
        /// <param name="newLine">indication of writing a new line character after current message</param>
        /// <param name="p">array of data objects to be written</param>
        protected override void writeInternal(MessageType message, bool newLine, params object[] p)
        {
            bool isWrite = true;

            switch (message)
            {
                case MessageType.Performence:
                    System.Console.Write(String.Format(LogTemplate.PERFORMANCE_REPORT, p));
                    break;
                case MessageType.NextPerformer:
                    System.Console.Write(String.Format(LogTemplate.NEXT_PERFORMER, p));
                    break;
                case MessageType.GameStats:
                    System.Console.Write(String.Format(LogTemplate.GAME_STATS, p));
                    break;
                case MessageType.LineSeperator:
                    System.Console.Write(System.Environment.NewLine);
                    break;
                case MessageType.NewLine:
                    System.Console.WriteLine();
                    break;
                case MessageType.ObservationsHeader:
                    System.Console.Write(String.Format(LogTemplate.OBSERVATIONS_OF_AGENT, p));
                    break;
                case MessageType.NumActions:
                    System.Console.Write(String.Format(LogTemplate.NUM_OF_ACTIONS_OF_AGENT, p));
                    break;
                case MessageType.ObservationsSoFar:
                    System.Console.Write(String.Format(LogTemplate.OBSERVATIONS_SO_FAR, p));
                    break;
                case MessageType.EstimatedCompetence:
                    System.Console.Write(String.Format(LogTemplate.ESTIMATING_COMPETENCE_OF_AGENT, p));
                    break;
                case MessageType.EstimatedEpsilon:
                    System.Console.Write(String.Format(LogTemplate.AGENT_EPSILON, p));
                    break;
                case MessageType.AgentActingAsExpected:
                    System.Console.Write(String.Format(LogTemplate.ACTING_AS_EXPECTED, p));
                    break;
                case MessageType.ObservationPrint:
                    System.Console.Write(string.Format(LogTemplate.OBSERVATION_PRINT, p));
                    break;
                case MessageType.OtherAgentCompetence:
                    System.Console.Write(string.Format(LogTemplate.COMPETENCE_OF_AGENT, p));
                    break;
                case MessageType.HowChoosingNextPlayer:
                    System.Console.Write(p);
                    break;
                case MessageType.OtherAgentMaxCompetence:
                    System.Console.Write(string.Format(LogTemplate.MAX_COMPETENCE_OF_AGENT, p));
                    break;
                default:
                    isWrite = false; //Used when there is no need to write the message
                    break;
            }

            if (newLine && isWrite)
                System.Console.WriteLine();
        }
    }
}
